const {WebSocket} = require("ws");
const {socketHost} = require("./config");
const {dialog} = require("electron");

const connect = ()=>{
    const ws = new WebSocket(socketHost)

    ws.onopen = (params)=>{
        dialog.showMessageBox({
            type: "info",
            title: "提示",
            message: "服务器连接成功,请移步小程序传输数据",
            buttons: ['确定']
        })
    }

    ws.onmessage =  (e) =>{
        console.log(e.data)
    }

    ws.onclose = (evt) =>{
        console.log("关闭客户端连接");
    }

    ws.onerror =  (evt) =>{
        dialog.showErrorBox("错误","服务器连接失败")
    }
    return ws
}


module.exports = {
    connect
}
